{% extends 'base.html' %}

{% load staticfiles %}

{% block title %}用户菜谱-学厨网{% endblock %}
{% block content %}
    <div class="container" style="margin-top: 70px;">
        <ol class="breadcrumb">
            <li><a href="{% url 'index' %}">首页</a></li>
            <li class="active">社区</li>
        </ol>
    </div>
    <div class="container">
        <!-- Example row of columns -->
        <div class="col-lg-8">
            <div class="page-header">
                <div class="clearfix">
                    <div class="pull-left">
                        <h2>{{ from_user.username }}</h2>
                    </div>
                    <div class="pull-right">
                        {% if is_concern == True %}
                            <button type="button" class="btn btn-default" id="add-fav" style="margin-top: 20px;">已关注
                            </button>
                        {% endif %}
                        {% if is_concern == False %}
                            <button type="button" class="btn btn-primary" id="add-fav" style="margin-top: 20px;">关注
                            </button>
                        {% endif %}
                    </div>
                </div>
            </div>
            {% for menu in menus.object_list %}
                <div class="row">
                    <div class="col-lg-3">
                        <div class="thumbnail">
                            <a href="{% url 'cookbook:cookbook_detail' menu.id %}"><img src="{{ MEDIA_URL }}{{ menu.image }}" alt="..."></a>
                        </div>
                    </div>
                    <div class="col-lg-9">
                        <div class="detail">
                            <h3>
                                <a href="{% url 'cookbook:cookbook_detail' menu.id %}">{{ menu.name }}</a>
                            </h3>

                            <p class="subcontent">原料：{{ menu.ingredients }}</p>

                            <div class="substatus clear">
                                <span><span class="glyphicon glyphicon-eye-open"
                                            aria-hidden="true"></span>&nbsp;{{ menu.click_number }}次查看</span>
                            </div>
                        </div>
                    </div>
                </div>
            {% endfor %}

            <!---分页--->
            <div class="pageturn" style="text-align: center">
                <ul class="pagelist">
                    {% load i18n %}
                    <div class="pagination">
                        {% if menus.has_previous %}
                            <li class="long"><a href="?{{ menus.previous_page_number.querystring }}"
                                                class="page">上一页</a></li>
                        {% endif %}
                        {% for page in menus.pages %}
                            {% if page %}
                                {% ifequal page menus.number %}
                                    <li class="active"><a href="?{{ page.querystring }}">{{ page }}</a></li>
                                {% else %}
                                    <li><a href="?{{ page.querystring }}" class="page">{{ page }}</a></li>
                                {% endifequal %}
                            {% else %}
                                <li class="none"><a href="">...</a></li>
                            {% endif %}
                        {% endfor %}
                        {% if menus.has_next %}
                            <li class="long"><a href="?{{ menus.next_page_number.querystring }}">下一页</a></li>
                        {% endif %}
                    </div>
                </ul>
            </div>

        </div>
        <div class="col-lg-4">
            <div style="margin-top: 40px;">
                {% for ad in ad_image %}
                    <a href="{{ ad.url }}"><img class="img-responsive center-block"
                                                src="{{ MEDIA_URL }}{{ ad.image }}" alt="..."></a>
                {% endfor %}
            </div>
            <div class="page-header">
                <h3>热门菜品</h3>
            </div>
            <div style="margin-bottom: 20px;">
                {% for hot_menu in hot_menus %}
                    <a href="{% url 'cookbook:cookbook_detail' hot_menu.id %}"
                       class="list-group-item ">{{ hot_menu.name }}</a>
                {% endfor %}
            </div>

        </div>

    </div> <!-- /container -->
    <script>
        $(function () {
            $('#add-fav').on('click', function () {
                $.ajax({
                    cache: false,
                    type: "POST",
                    url: "{% url 'cookbook:cookbook_add_concern' %}",
                    data: {
                        from_user: {{ from_user.id }},
                        csrfmiddlewaretoken: '{{ csrf_token }}'
                    },
                    success: function (data) {
                        if (data.status === 1) {
                            $('#add-fav').html('已关注');
                            $('#add-fav').removeClass('btn-primary').addClass('btn-default');
                        }
                        else if (data.status === 2) {
                            $('#add-fav').html('关注');
                            $('#add-fav').removeClass('btn-default').addClass('btn-primary');
                        }
                        else
                            window.location.href = "{% url 'login' %}";
                    }
                })
            })
        });
    </script>

    <script type="text/javascript" src="{% static "ckeditor/ckeditor-init.js" %}"></script>
    <script type="text/javascript" src="{% static "ckeditor/ckeditor/ckeditor.js" %}"></script>
{% endblock %}